package com.ebs.md.api.comparators;

/**
 * Revision Author:
 *  $File: //depot/MarketData/commons-md-api/MAIN/src/main/java/com/ebs/md/api/comparators/MdComparators.java $
 *  $Revision: #1 $
 *  $DateTime: 2012/04/29 09:26:44 $
 *  $Change: 110636 $
 *  $Author: Arik.Sher $
 */

import java.util.Comparator;

import com.ebs.md.api.Rate;

public final class MdComparators 
{
	private MdComparators() {}
	
	
	public static final Comparator<Rate>   bidRateComperator = new BidRateComparator(); 
	public static final Comparator<Rate> offerRateComperator = new OfferRateComparator(); 
	
	// larger numbers should be first (3,2,1). nulls should be last
	public static class BidRateComparator 
	implements Comparator<Rate> 
	{
		public int compare(Rate o1, Rate o2) {
			if ( o1 == null ) {
				if ( o2 == null ) {
					return 0;
				} else {
					return 1;
				}
			}
			if ( o2 == null ) {
				return -1;
			}
			
			return o2.getValue().compareTo(
				   o1.getValue() );
		}
	}

	// lower numbers should be first (1,2,3). nulls should be last
	public static class OfferRateComparator 
	implements Comparator<Rate> 
	{
		public int compare(Rate o1, Rate o2) {
			if ( o1 == null ) {
				if ( o2 == null ) {
					return 0;
				} else {
					return 1;
				}
			}
			if ( o2 == null ) {
				return -1;
			}
			
			return o1.getValue().compareTo(
				   o2.getValue() );
		}
	}

}
